<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-DRC-doctor-widget" :style="getStyle('head')">
      <!--科室信息-->
      <div class="dept-room" :class="{'dept-room-hide':((optionsInfo?.checkList?.length)===1 || optionsInfo['deptHide'])}">
        <p class="dept" v-if="(optionsInfo.checkList).includes(1) || optionsInfo['deptHide']" :style="getStyle('roomInfo')">
          <ScrollX>
            {{ getRoomDeptInfo[optionsInfo['deptNameKey'] || 'deptName'] || '\u00a0' }}
          </ScrollX>
        </p>
        <p class="room" v-if="(optionsInfo.checkList).includes(3) || optionsInfo['roomHide']" :style="getStyle('roomInfo')">
          <ScrollX>
            {{ getRoomDeptInfo[optionsInfo['roomNameKey'] || 'roomName'] || '\u00a0' }}
          </ScrollX>
        </p>
      </div>
      <!--医生信息-->
      <template v-for="item in getRoomDoctorInfo">
        <div class="doctor-info flex-box">
          <div class="picture flex-box-left">
            <img
                alt="医生"
                @error='handleError'
                :src="(item.workerPicture) || '/tpleditor/resource/assets/images/header.png'">
          </div>
          <div class="info flex-box-right" :style="getStyle('doctorInfo')">
            <div class="name">{{ (item.workerName) || '\u00a0' }}</div>
            <div class="level">{{ (item.workerTitle) || '\u00a0' }}</div>
          </div>
        </div>
        <div class="doctor-desc">
          <div class="doctor-title">医生简介</div>
          <div class="doctor-connect">
            <div class="container">
              <ScrollY :content="item.workerIntro || '\u00a0'" :pageDuration="10"/>
            </div>
          </div>
        </div>
      </template>
    </div>
  </CompOperate>
</template>

<script>
import {pxToVw} from '@/utils/common';
import emitter from "@/utils/designer/emitter";
import {buildParentApi} from "@/utils/designer/util";
import ScrollY from '@c/public/seamlessScroll/ScrollY.vue'
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import ScrollX from "@c/public/seamlessScroll/ScrollX.vue";

let buildParent = buildParentApi();
export default {
  name: "scene-DRC-doctor-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    ScrollX,
    CompOperate,
    ScrollY
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
    //prop传入的表单JSON配置
    parentApi: {
      type: Object,
      default: () => buildParentApi()
    },
  },

  data() {
    return {
      states: true,
      optionsInfo:Object(),
      header: require("@a/images/design/header.jpeg"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'head':
            Reflect.set(Obj, 'height', pxToVw(info.headHeight));
            Reflect.set(Obj, 'backgroundColor', `${(info.backgroundColor)}`);
            return Obj;
          case 'roomInfo':
            Reflect.set(Obj, 'color', (info.roomInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.roomInfoFontWeight));
            return Obj;
          case 'doctorInfo':
            Reflect.set(Obj, 'fontWeight', (info.doctorInfoFontWeight));
            return Obj;
          case 'patientInfo':
            Reflect.set(Obj, 'fontWeight', (info.patientInfoFontWeight));
            return Obj;
          case 'tipsSign':
            Reflect.set(Obj, 'color', (info.tipsTitleInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.tipsTitleInfoFontWeight));
            return Obj;
          case 'passPatient':
            Reflect.set(Obj, 'color', (info.passPatientInfoColor));
            Reflect.set(Obj, 'fontWeight', (info.passPatientInfoFontWeight));
            return Obj;
        }
      }
    },

    // 获取全量医患信息
    getRoomDoctorInfo() {
      let temp = Array();
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getRoomDoctorInfo'];
      if (devType) {
        if (!!(roomDoctorInfo.apiData?.length)) {
          return roomDoctorInfo.apiData.slice(0, 1);
        } else {
          return temp.push({});
        }
      } else {
        if (!!(roomDoctorInfo.mockData?.length)) {
          return roomDoctorInfo.mockData.slice(0, 1);
        } else {
          return temp.push({});
        }
      }
    },

    // 获取科室信息
    getRoomDeptInfo() {
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getRoomDeptInfo'];
      if (devType) {
        return roomDoctorInfo.apiData;
      } else {
        return roomDoctorInfo.mockData;
      }
    },

  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "roomDeptInfo":
          console.log(`科室信息-${data}`)
          this.states = true;
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign: '模板-科室信息', key: key, data: data}))
          // this.parentApi.executeParentMethod('writeLog', JSON.stringify({sign:'模板日志-医生信息',key:key,data:data}));
          this.$store.dispatch('setRoomDeptInfo', data)
          break
        case "roomDoctorInfo":
          console.log(`医生信息-${data}`);
          this.states = true;
          // this.parentApi.executeParentMethod('writeLog', JSON.stringify({sign:'模板日志-科室信息',key:key,data:data}));
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign: '模板-医生信息', key: key, data: data}))
          this.$store.dispatch('setRoomDoctorInfo', this.$lodash.cloneDeep(data))
          break
      }
    },

    handleError(event) {
      const loadedImg = event.target;
      this.states = false;
    }
  },

  watch: {
    field: {
      handler: function (val) {
        let key = val.options.config
        this.optionsInfo = val.options[key];
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-DRC-doctor-widget {
  padding: 28px 30px;
  box-sizing: border-box;
  flex: inherit;
  flex-direction: column;
  justify-content: space-between;
  color: #333;
  height: 150px;
  font-size: 40px;
  background: transparent;
  overflow: hidden;
  //科室
  .dept-room {
    padding: 20px 0 8px 0;
    background: #0059B3;
    border-radius: 20px;
    height: 314px;
    overflow: hidden;

    p {
      color: #FFFFFF;
      text-align: center;
      font-size: 80px;
    }

    .dept {
      font-size: 80px;
      line-height: 120px;
      @include singleEllipsis(100%)
    }

    .room {
      font-size: 120px;
      font-weight: normal;
      line-height: 180px;
      @include singleEllipsis(100%);
      min-height: 170px;
    }
  }

  .dept-room-hide {
    display: flex;
    align-items: center;
    align-self: center;
  }

  //医生信息
  .doctor-info {
    height: 486px;
    display: flex;
    margin: 48px 0 48px 0;
    min-width: auto;

    .picture {
      flex: inherit;
      border-radius: 20px;
      overflow: hidden;
      width: 358px;
      border: none;
      max-height: 486px;
      background: transparent;
      flex-shrink: 0;

      img {
        width: 100%;
      }
    }

    .info {
      flex: inherit;
      display: flex;
      flex-direction: column;
      width: calc(100% - 358px);
      padding-left: 30px;
      border: none;
      background: transparent;

      .name {
        font-size: 80px;
        line-height: 120px;
      }

      .level {
        font-size: 50px;
        line-height: 74px;
        padding-top: 8px;
        padding-bottom: 26px;
      }
    }
  }

  //医生介绍
  .doctor-desc {
    font-size: 32px;
    line-height: 52px;
    border-radius: 20px;
    overflow: hidden;
    background: white;
    border: 2px solid rgba(144, 147, 153, 0.3);
    box-shadow: rgba(50, 50, 93, 0.15) 0 50px 100px -20px, rgba(0, 0, 0, 0.15) 0px 30px 60px -30px;

    .doctor-title {
      color: rgba(0, 89, 179, 1);
      padding: 32px 0;
      text-align: center;
      background: white;
      font-size: 50px;
      font-weight: 500;
      border-bottom: 2px solid #909399;
    }

    .doctor-connect {
      font-size: 40px;
      line-height: 82px;
      text-indent: 2em;
      padding: 38px 50px 0 38px;
      margin-bottom: 34px;
      height: 500px;
      overflow: hidden;

      .container {
        height: 100%;
      }
    }
  }
}
</style>
